package com.ydx.Controller;

import com.ydx.entity.Shiyanshi;
import com.ydx.service.ShiyanshiService;
import com.ydx.util.JsonResponse2;
import com.ydx.util.ResponseData2;
import jakarta.annotation.Resource;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/Shiyanshi")
public class ShiyanshiController {

    @Resource
    private ShiyanshiService shiyanshiService;

    @GetMapping("/ShiyanshiList")
    public JsonResponse2 ShiyanshiList() {
        List<Shiyanshi> shiyanshis = shiyanshiService.list();
        System.out.println("来到了实验室查询");
        // 构建自定义的响应数据格式
        JsonResponse2 response = new JsonResponse2();
        response.setCode(200);
        response.setMessage("成功!");
        ResponseData2 result = new ResponseData2();
        result.setTotal(shiyanshis.size());
        result.setList(shiyanshis);
        response.setResult(result);
        return response;
    }

    @GetMapping("/WodeList/{userid}")
    public JsonResponse2 WodeList(@PathVariable int userid) {
        List<Shiyanshi> shiyanshis = shiyanshiService.SelectByUserid(userid);
        System.out.println("来到了我的实验室查询");
        // 构建自定义的响应数据格式
        JsonResponse2 response = new JsonResponse2();
        response.setCode(200);
        response.setMessage("成功!");
        ResponseData2 result = new ResponseData2();
        result.setTotal(shiyanshis.size());
        result.setList(shiyanshis);
        response.setResult(result);
        return response;
    }

    @DeleteMapping("/DeleteShiyanshi/{shiyanshiid}")
    public boolean DeleteUser(@PathVariable int shiyanshiid) {
        System.out.println("删除");
        return shiyanshiService.removeById(shiyanshiid);
    }

    @PutMapping("/AddShiyanshi")
    public boolean AddUser(@RequestBody Shiyanshi shiyanshi) {
        System.out.println(shiyanshi);
        System.out.println("新增");
        return shiyanshiService.save(shiyanshi);
    }

    @PostMapping("/UpdateShiyanshi")
    public boolean UpdateUser(@RequestBody Shiyanshi shiyanshi) {
        return shiyanshiService.updateById(shiyanshi);
    }
}
